/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Alberto, Alessandra
 */
@Entity
//@Table(name = "EVENT")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("OutdoorEvent")
@NamedQueries({
    @NamedQuery(
                name = "findOutdoorEventByDate",
                query = "SELECT e FROM OutdoorEvent e WHERE e.date = :Edate"
    ),
    @NamedQuery(
                name = "findOutdoorEventInFuture",
                query = "SELECT e FROM OutdoorEvent e WHERE e.date >= CURRENT_DATE"
    )
})
public class OutdoorEvent extends Event implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @ManyToOne
    @JoinColumn(name = "idweather", referencedColumnName = "id")
    private WeatherForecast weatherforecast;
    
    @ManyToMany
    @JoinTable(
            name = "BadWeather",
            joinColumns = 
                    @JoinColumn(name = "idevent", referencedColumnName = "id"),
            inverseJoinColumns = 
                     @JoinColumn(name = "idweather", referencedColumnName = "id")
    )
    private Collection<WeatherForecast> badweather;
    
    @OneToMany(mappedBy = "event")
    private Collection<OneDayNotification> onedaynotifications;
    
    @OneToMany(mappedBy = "event")
    private Collection<ThreeDaysNotification> threedaysnotifications;
    
    public OutdoorEvent () {
        super();
    }

    public OutdoorEvent(Collection<WeatherForecast> badweather, String name, Boolean visibility, Integer starthour, Integer startminute, Integer endhour, Integer endminute, Date date, String description, User creator, Place place) {
        super(name, visibility, starthour, startminute, endhour, endminute, date, description, creator, place);
        this.weatherforecast = null;
        this.badweather = badweather;
        this.threedaysnotifications = new ArrayList<ThreeDaysNotification>();
        this.onedaynotifications = new ArrayList<OneDayNotification>();
    }

    public WeatherForecast getWeatherforecast() {
        return weatherforecast;
    }

    public void setWeatherforecast(WeatherForecast weatherforecast) {
        this.weatherforecast = weatherforecast;
    }

    public Collection<WeatherForecast> getBadweather() {
        return badweather;
    }

    public void setBadweather(Collection<WeatherForecast> badweather) {
        this.badweather = badweather;
    }

    public Collection<OneDayNotification> getOnedaynotifications() {
        return onedaynotifications;
    }

    public void setOnedaynotifications(Collection<OneDayNotification> onedaynotifications) {
        this.onedaynotifications = onedaynotifications;
    }

    public Collection<ThreeDaysNotification> getThreedaysnotifications() {
        return threedaysnotifications;
    }

    public void setThreedaysnotifications(Collection<ThreeDaysNotification> threedaysnotifications) {
        this.threedaysnotifications = threedaysnotifications;
    }
    
    public void addOneDayNotification (OneDayNotification notification) {
        this.onedaynotifications.add(notification);
    }
    
    public void removeOneDayNotification (OneDayNotification notification) {
        this.onedaynotifications.remove(notification);
    }
    
    public void addThreeDaysNotification (ThreeDaysNotification notification) {
        this.threedaysnotifications.add(notification);
    }
    
    public void removeThreeDaysNotification (ThreeDaysNotification notification) {
        this.threedaysnotifications.remove(notification);
    }
    
    public Boolean isBadWeather () {
        if (badweather.contains(weatherforecast))
            return true;
        else
            return false;
    }
    
    public Boolean isForecasted () {
        return weatherforecast != null;
    }
    
}
